<?php

namespace App\Http\model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class Test extends Model
{
	/**
	 * [setLinesModel 修改上下线]
	 * @Author   孙丽男
	 * @DateTime 2018-06-11
	 * @param    [type]
	 * @version  6.2
	 */
	public function setLinesModel($id,$is_zx){
		$result = array();
		//查询是否有未结束订单
		$order = Db::table('driver')
			->where('id',$id)
			->json('order_extend','order_extend.driver_id','=','driver.id')
			->join('order','order.extendid','=','order_extend.id')
			->select('order.orderstatus')
			->get();
		$orderArr = json_decode(json_encode($order),true);
		$res = '';
		foreach ($orderArr as $key => $value) {
			if ($value['orderstatus'] != 9) {
				$res = 1;
			}
		}
		if ($res) {
			
			$result['code'] = 1003;
			$result['msg'] = '还有订单未结束';
			return json_encode($result);
		}

		$data['is_zx'] = $is_zx;
		$update = Db::table('driver')
			->where('id',$id)
			->update($data)
		if ($update) {
			$result['code'] = 1000;
			$result['msg'] = '修改成功';
		}else{
			$result['code'] = 1004;
			$result['msg'] = '修改失败';
		}
		return json_encode($result);
	}
}